#!/usr/bin/env Rscript
##################################
############ Preamble ############
##################################
# set language to English
Sys.setenv(LANG = "en")

# clean up
rm(list = ls())

# Set working directory: Please set your own
if (Sys.getenv("RSTUDIO") == "1") setwd("~/Dropbox/cues_bjps_replication")

library(Rmisc)
library(tidyverse)
library(readxl)
library(stargazer)
library(kableExtra)
library(sandwich)
library(broom)
library(dotwhisker)
library(jtools)
library(scales)



# read data
raw_data <- read_xlsx("data/final_survey_data.xlsx")

# rename variables
raw_data <- raw_data %>%
  dplyr::rename(
    number = lfdn,
    completion_time = duration,
    disposition_code = dispcode,
    treatment = c_0031,
    cover_page = v_27,
    age = v_28,
    age_range = v_29,
    gender = v_30,
    state = v_31,
    born_in_germany = v_39,
    sign_petition_self = v_47,
    sensitive_item_agree = dupl1_v_44,
    left_right = dupl1_v_41,
    petition_appropriate_self = v_48,
    sign_petition_others = v_49,
    petition_appropriate_others = v_50,
    delete_tweet = v_51,
    voted_2021 = v_53,
    party_voted_2021 = v_54,
    party_voted_2021_other_which = v_55,
    voted_2017 = v_56,
    party_voted_2017 = v_57,
    party_voted_2017_other_which = v_58,
    household_income = v_59,
    education = v_60,
    mother_born_where = v_61,
    mother_born_other_where = v_62,
    father_born_where = v_63,
    father_born_other_where = v_64
  )

raw_data <- raw_data %>%
  mutate(treatment = replace(treatment, which(treatment == 1), "Mainstream Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 2), "Mainstream Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 3), "RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 4), "RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 5), "Mainstream and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 6), "Mainstream and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 7), "Mainstream Disapprove and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 8), "Mainstream Disapprove and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 9), "Control")) %>%
  mutate(treatment = replace(treatment, which(treatment == 10), "Control"))

# recode state names
raw_data <- raw_data %>%
  mutate(state = replace(state, which(state == 1), "Baden-Wuerttemberg")) %>%
  mutate(state = replace(state, which(state == 2), "Bayern")) %>%
  mutate(state = replace(state, which(state == 3), "Berlin")) %>%
  mutate(state = replace(state, which(state == 4), "Brandenburg")) %>%
  mutate(state = replace(state, which(state == 5), "Bremen")) %>%
  mutate(state = replace(state, which(state == 6), "Hamburg")) %>%
  mutate(state = replace(state, which(state == 7), "Hessen")) %>%
  mutate(state = replace(state, which(state == 8), "Mecklenburg-Vorpommern")) %>%
  mutate(state = replace(state, which(state == 9), "Niedersachsen")) %>%
  mutate(state = replace(state, which(state == 10), "Nordrhein-Westfalen")) %>%
  mutate(state = replace(state, which(state == 11), "Rheinland-Pfalz")) %>%
  mutate(state = replace(state, which(state == 12), "Saarland")) %>%
  mutate(state = replace(state, which(state == 13), "Sachsen")) %>%
  mutate(state = replace(state, which(state == 14), "Sachsen-Anhalt")) %>%
  mutate(state = replace(state, which(state == 15), "Schleswig-Holstein")) %>%
  mutate(state = replace(state, which(state == 16), "Thueringen"))

# recode age_ranges
raw_data <- raw_data %>%
  mutate(age_range = replace(age_range, which(age_range == 1), "18 - 29 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 2), "30 - 39 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 3), "40 - 49 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 4), "50 - 59 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 5), "60 - 90 years"))

# recode gender
raw_data <- raw_data %>%
  mutate(gender = replace(gender, which(gender == 1), "Male")) %>%
  mutate(gender = replace(gender, which(gender == 2), "Female"))

# recode sensitive item - change sensitive item response "disagree" to 0
raw_data <- raw_data %>%
  mutate(sensitive_item_agree = replace(sensitive_item_agree, which(sensitive_item_agree == 2), 0))

# recode coordination game - change "not willing to sign" from 2 to 0
raw_data <- raw_data %>%
  mutate(sign_petition_self = replace(sign_petition_self, which(sign_petition_self == 2), 0))

# recode punishment exp - change "do not delete tweet" from 2 to 0
raw_data <- raw_data %>%
  mutate(delete_tweet = replace(delete_tweet, which(delete_tweet == 2), 0))

# recode left_right 100 is 0, 99 is NA
raw_data <- raw_data %>%
  mutate(left_right = replace(left_right, which(left_right == 100), 0)) %>%
  mutate(left_right = replace(left_right, which(left_right == 99), NA))

raw_data <- raw_data %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 1), "CDU/CSU")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 2), "SPD")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 3), "AfD")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 4), "Green")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 5), "FDP")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 6), "Die Linke"))

# remove incompletes or inattentives
analysis_data <- raw_data %>%
  filter(disposition_code == "31" | disposition_code == "32")

# clean up sensitive item - drop -77s, merge both columns
analysis_data <- analysis_data %>%
  mutate(sensitive_item_agree = replace(sensitive_item_agree, which(sensitive_item_agree < 0), NA))

# Create dummy variable
analysis_data$MRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream Approve", 1, 0)
analysis_data$RRPapprovedummy <- ifelse(analysis_data$treatment == "RRP Approve", 1, 0)
analysis_data$MRPapproveRRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream and RRP Approve", 1, 0)
analysis_data$MRPdisapproveRRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream Disapprove and RRP Approve", 1, 0)

# mainstream only
mainstream_only <- analysis_data %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only <- analysis_data %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only <- analysis_data %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only <- analysis_data %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data[, c(18, 19, 20, 21, 22, 23)])
left_only[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only[, c(18, 19, 20, 21, 22, 23)])
right_only[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only[, c(18, 19, 20, 21, 22, 23)])
# rrp_only[,c(18,19,20,21,22,23)]<-scale(rrp_only[,c(18,19,20,21,22,23)])



# Sensitive Item - remove age

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_removeage <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = analysis_data)
sensitive_item_controls_leftonly_removeage <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = left_only)
sensitive_item_controls_rightonly_removeage <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = right_only)
# sensitive_item_controls_rrponly_removeage <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = rrp_only)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_removeage <- summ(sensitive_item_controls_fullsample_removeage, robust = "HC1")
robust_sensitive_item_controls_leftonly_removeage <- summ(sensitive_item_controls_leftonly_removeage, robust = "HC1")
robust_sensitive_item_controls_rightonly_removeage <- summ(sensitive_item_controls_rightonly_removeage, robust = "HC1")
# robust_sensitive_item_controls_rrponly_removeage <- summ(sensitive_item_controls_rrponly_removeage, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_removeage_df <- broom::tidy(robust_sensitive_item_controls_fullsample_removeage) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_removeage_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_removeage_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_removeage_df <- broom::tidy(robust_sensitive_item_controls_leftonly_removeage) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_removeage_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_removeage_df)[7] <- "term"


robust_sensitive_item_controls_rightonly_removeage_df <- broom::tidy(robust_sensitive_item_controls_rightonly_removeage) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_removeage_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_removeage_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_removeage_df <- broom::tidy(robust_sensitive_item_controls_rrponly_removeage) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_removeage_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_removeage_df)[7] <- "term"


# Willingness to Sign Petition - remove age


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_removeage <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = analysis_data)
sign_petition_self_controls_leftonly_removeage <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = left_only)
sign_petition_self_controls_rightonly_removeage <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = right_only)
# sign_petition_self_controls_rrponly_removeage <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = rrp_only)

# robust SEs
robust_sign_petition_self_controls_fullsample_removeage <- summ(sign_petition_self_controls_fullsample_removeage, robust = "HC1")
robust_sign_petition_self_controls_leftonly_removeage <- summ(sign_petition_self_controls_leftonly_removeage, robust = "HC1")
robust_sign_petition_self_controls_rightonly_removeage <- summ(sign_petition_self_controls_rightonly_removeage, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_removeage <- summ(sign_petition_self_controls_rrponly_removeage, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_removeage_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_removeage) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_removeage_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_removeage_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_removeage_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_removeage) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_removeage_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_removeage_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_removeage_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_removeage) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_removeage_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_removeage_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_removeage_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_removeage) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_removeage_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_removeage_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - remove age

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_removeage <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = analysis_data)
petition_appropriate_self_controls_leftonly_removeage <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = left_only)
petition_appropriate_self_controls_rightonly_removeage <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = right_only)
# petition_appropriate_self_controls_rrponly_removeage <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = rrp_only)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_removeage <- summ(petition_appropriate_self_controls_fullsample_removeage, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_removeage <- summ(petition_appropriate_self_controls_leftonly_removeage, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_removeage <- summ(petition_appropriate_self_controls_rightonly_removeage, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_removeage <- summ(petition_appropriate_self_controls_rrponly_removeage, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_removeage_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_removeage) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_removeage_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_removeage_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_removeage_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_removeage) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_removeage_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_removeage_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_removeage_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_removeage) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_removeage_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_removeage_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_removeage_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_removeage) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_removeage_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_removeage_df)[7] <- "term"



# Empirical Expectations - remove age

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_removeage <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education + left_right, data = analysis_data)
sign_petition_others_controls_leftonly_removeage <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education + left_right, data = left_only)
sign_petition_others_controls_rightonly_removeage <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education + left_right, data = right_only)
# sign_petition_others_controls_rrponly_removeage <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + education + left_right, data = rrp_only)

# robust SEs
robust_sign_petition_others_controls_fullsample_removeage <- summ(sign_petition_others_controls_fullsample_removeage, robust = "HC1")
robust_sign_petition_others_controls_leftonly_removeage <- summ(sign_petition_others_controls_leftonly_removeage, robust = "HC1")
robust_sign_petition_others_controls_rightonly_removeage <- summ(sign_petition_others_controls_rightonly_removeage, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_removeage <- summ(sign_petition_others_controls_rrponly_removeage, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_removeage_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_removeage) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_removeage_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_removeage_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_removeage_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_removeage) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_removeage_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_removeage_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_removeage_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_removeage) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_removeage_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_removeage_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_removeage_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_removeage) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_removeage_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_removeage_df)[7] <- "term"



# Normative Expectations - remove age

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_removeage <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = analysis_data)
petition_appropriate_others_controls_leftonly_removeage <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = left_only)
petition_appropriate_others_controls_rightonly_removeage <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = right_only)
# petition_appropriate_others_controls_rrponly_removeage <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy  + household_income + education + left_right, data = rrp_only)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_removeage <- summ(petition_appropriate_others_controls_fullsample_removeage, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_removeage <- summ(petition_appropriate_others_controls_leftonly_removeage, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_removeage <- summ(petition_appropriate_others_controls_rightonly_removeage, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_removeage <- summ(petition_appropriate_others_controls_rrponly_removeage, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_removeage_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_removeage) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_removeage_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_removeage_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_removeage_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_removeage) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_removeage_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_removeage_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_removeage_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_removeage) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_removeage_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_removeage_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_removeage_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_removeage) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_removeage_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_removeage_df)[7] <- "term"



# Sanctioning - remove age

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_removeage <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = analysis_data)
delete_tweet_controls_leftonly_removeage <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = left_only)
delete_tweet_controls_rightonly_removeage <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + household_income + education + left_right, data = right_only)
# delete_tweet_controls_rrponly_removeage <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  household_income + education + left_right, data = rrp_only)

# robust SEs
robust_delete_tweet_controls_fullsample_removeage <- summ(delete_tweet_controls_fullsample_removeage, robust = "HC1")
robust_delete_tweet_controls_leftonly_removeage <- summ(delete_tweet_controls_leftonly_removeage, robust = "HC1")
robust_delete_tweet_controls_rightonly_removeage <- summ(delete_tweet_controls_rightonly_removeage, robust = "HC1")
# robust_delete_tweet_controls_rrponly_removeage <- summ(delete_tweet_controls_rrponly_removeage, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_removeage_df <- broom::tidy(robust_delete_tweet_controls_fullsample_removeage) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_removeage_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_removeage_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_removeage_df <- broom::tidy(robust_delete_tweet_controls_leftonly_removeage) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_removeage_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_removeage_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_removeage_df <- broom::tidy(robust_delete_tweet_controls_rightonly_removeage) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_removeage_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_removeage_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_removeage_df <- broom::tidy(robust_delete_tweet_controls_rrponly_removeage) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_removeage_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_removeage_df)[7] <- "term"

# final joining of all the models
joined_models_controls_removeage <- rbind(
  robust_sign_petition_self_controls_fullsample_removeage_df,
  robust_sign_petition_self_controls_leftonly_removeage_df,
  robust_sign_petition_self_controls_rightonly_removeage_df,
  # robust_sign_petition_self_controls_rrponly_removeage_df,
  robust_sensitive_item_controls_fullsample_removeage_df,
  robust_sensitive_item_controls_leftonly_removeage_df,
  robust_sensitive_item_controls_rightonly_removeage_df,
  # robust_sensitive_item_controls_rrponly_removeage_df,
  robust_petition_appropriate_self_controls_fullsample_removeage_df,
  robust_petition_appropriate_self_controls_leftonly_removeage_df,
  robust_petition_appropriate_self_controls_rightonly_removeage_df,
  # robust_petition_appropriate_self_controls_rrponly_removeage_df,
  robust_sign_petition_others_controls_fullsample_removeage_df,
  robust_sign_petition_others_controls_leftonly_removeage_df,
  robust_sign_petition_others_controls_rightonly_removeage_df,
  # robust_sign_petition_others_controls_rrponly_removeage_df,
  robust_petition_appropriate_others_controls_fullsample_removeage_df,
  robust_petition_appropriate_others_controls_leftonly_removeage_df,
  robust_petition_appropriate_others_controls_rightonly_removeage_df,
  # robust_petition_appropriate_others_controls_rrponly_removeage_df,
  robust_delete_tweet_controls_fullsample_removeage_df,
  robust_delete_tweet_controls_leftonly_removeage_df,
  robust_delete_tweet_controls_rightonly_removeage_df
  # robust_delete_tweet_controls_rrponly_removeage_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_removeage$sample <- factor(joined_models_controls_removeage$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e13 <- dwplot(joined_models_controls_removeage,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Treatment Conditions against Control Condition (With Controls, Age Removed)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e13.png", plot = fig_e13,
  width = 15, height = 10
)



# Sensitive Item - Remove income

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_removeincome <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data)
sensitive_item_controls_leftonly_removeincome <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only)
sensitive_item_controls_rightonly_removeincome <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only)
# sensitive_item_controls_rrponly_removeincome <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_removeincome <- summ(sensitive_item_controls_fullsample_removeincome, robust = "HC1")
robust_sensitive_item_controls_leftonly_removeincome <- summ(sensitive_item_controls_leftonly_removeincome, robust = "HC1")
robust_sensitive_item_controls_rightonly_removeincome <- summ(sensitive_item_controls_rightonly_removeincome, robust = "HC1")
# robust_sensitive_item_controls_rrponly_removeincome <- summ(sensitive_item_controls_rrponly_removeincome, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_removeincome_df <- broom::tidy(robust_sensitive_item_controls_fullsample_removeincome) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_removeincome_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_removeincome_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_removeincome_df <- broom::tidy(robust_sensitive_item_controls_leftonly_removeincome) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_removeincome_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_removeincome_df)[7] <- "term"


robust_sensitive_item_controls_rightonly_removeincome_df <- broom::tidy(robust_sensitive_item_controls_rightonly_removeincome) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_removeincome_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_removeincome_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_removeincome_df <- broom::tidy(robust_sensitive_item_controls_rrponly_removeincome) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_removeincome_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_removeincome_df)[7] <- "term"


# Willingness to Sign Petition- remove income


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_removeincome <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data)
sign_petition_self_controls_leftonly_removeincome <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only)
sign_petition_self_controls_rightonly_removeincome <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only)
# sign_petition_self_controls_rrponly_removeincome <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only)

# robust SEs
robust_sign_petition_self_controls_fullsample_removeincome <- summ(sign_petition_self_controls_fullsample_removeincome, robust = "HC1")
robust_sign_petition_self_controls_leftonly_removeincome <- summ(sign_petition_self_controls_leftonly_removeincome, robust = "HC1")
robust_sign_petition_self_controls_rightonly_removeincome <- summ(sign_petition_self_controls_rightonly_removeincome, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_removeincome <- summ(sign_petition_self_controls_rrponly_removeincome, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_removeincome_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_removeincome) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_removeincome_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_removeincome_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_removeincome_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_removeincome) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_removeincome_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_removeincome_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_removeincome_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_removeincome) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_removeincome_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_removeincome_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_removeincome_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_removeincome) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_removeincome_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_removeincome_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - remove income

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_removeincome <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data)
petition_appropriate_self_controls_leftonly_removeincome <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only)
petition_appropriate_self_controls_rightonly_removeincome <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only)
# petition_appropriate_self_controls_rrponly_removeincome <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age  + education + left_right, data = rrp_only)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_removeincome <- summ(petition_appropriate_self_controls_fullsample_removeincome, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_removeincome <- summ(petition_appropriate_self_controls_leftonly_removeincome, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_removeincome <- summ(petition_appropriate_self_controls_rightonly_removeincome, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_removeincome <- summ(petition_appropriate_self_controls_rrponly_removeincome, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_removeincome_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_removeincome) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_removeincome_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_removeincome_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_removeincome_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_removeincome) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_removeincome_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_removeincome_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_removeincome_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_removeincome) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_removeincome_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_removeincome_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_removeincome_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_removeincome) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_removeincome_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_removeincome_df)[7] <- "term"



# Empirical Expectations - remove income

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_removeincome <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data)
sign_petition_others_controls_leftonly_removeincome <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only)
sign_petition_others_controls_rightonly_removeincome <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only)
# sign_petition_others_controls_rrponly_removeincome <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only)

# robust SEs
robust_sign_petition_others_controls_fullsample_removeincome <- summ(sign_petition_others_controls_fullsample_removeincome, robust = "HC1")
robust_sign_petition_others_controls_leftonly_removeincome <- summ(sign_petition_others_controls_leftonly_removeincome, robust = "HC1")
robust_sign_petition_others_controls_rightonly_removeincome <- summ(sign_petition_others_controls_rightonly_removeincome, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_removeincome <- summ(sign_petition_others_controls_rrponly_removeincome, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_removeincome_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_removeincome) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_removeincome_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_removeincome_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_removeincome_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_removeincome) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_removeincome_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_removeincome_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_removeincome_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_removeincome) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_removeincome_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_removeincome_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_removeincome_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_removeincome) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_removeincome_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_removeincome_df)[7] <- "term"



# Normative Expectations - remove income

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_removeincome <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data)
petition_appropriate_others_controls_leftonly_removeincome <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only)
petition_appropriate_others_controls_rightonly_removeincome <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only)
# petition_appropriate_others_controls_rrponly_removeincome <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_removeincome <- summ(petition_appropriate_others_controls_fullsample_removeincome, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_removeincome <- summ(petition_appropriate_others_controls_leftonly_removeincome, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_removeincome <- summ(petition_appropriate_others_controls_rightonly_removeincome, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_removeincome <- summ(petition_appropriate_others_controls_rrponly_removeincome, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_removeincome_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_removeincome) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_removeincome_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_removeincome_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_removeincome_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_removeincome) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_removeincome_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_removeincome_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_removeincome_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_removeincome) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_removeincome_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_removeincome_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_removeincome_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_removeincome) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_removeincome_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_removeincome_df)[7] <- "term"



# Sanctioning - remove income

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_removeincome <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data)
delete_tweet_controls_leftonly_removeincome <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only)
delete_tweet_controls_rightonly_removeincome <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only)
# delete_tweet_controls_rrponly_removeincome <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only)

# robust SEs
robust_delete_tweet_controls_fullsample_removeincome <- summ(delete_tweet_controls_fullsample_removeincome, robust = "HC1")
robust_delete_tweet_controls_leftonly_removeincome <- summ(delete_tweet_controls_leftonly_removeincome, robust = "HC1")
robust_delete_tweet_controls_rightonly_removeincome <- summ(delete_tweet_controls_rightonly_removeincome, robust = "HC1")
# robust_delete_tweet_controls_rrponly_removeincome <- summ(delete_tweet_controls_rrponly_removeincome, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_removeincome_df <- broom::tidy(robust_delete_tweet_controls_fullsample_removeincome) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_removeincome_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_removeincome_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_removeincome_df <- broom::tidy(robust_delete_tweet_controls_leftonly_removeincome) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_removeincome_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_removeincome_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_removeincome_df <- broom::tidy(robust_delete_tweet_controls_rightonly_removeincome) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_removeincome_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_removeincome_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_removeincome_df <- broom::tidy(robust_delete_tweet_controls_rrponly_removeincome) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_removeincome_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_removeincome_df)[7] <- "term"

# final joining of all the models
joined_models_controls_removeincome <- rbind(
  robust_sign_petition_self_controls_fullsample_removeincome_df,
  robust_sign_petition_self_controls_leftonly_removeincome_df,
  robust_sign_petition_self_controls_rightonly_removeincome_df,
  # robust_sign_petition_self_controls_rrponly_removeincome_df,
  robust_sensitive_item_controls_fullsample_removeincome_df,
  robust_sensitive_item_controls_leftonly_removeincome_df,
  robust_sensitive_item_controls_rightonly_removeincome_df,
  # robust_sensitive_item_controls_rrponly_removeincome_df,
  robust_petition_appropriate_self_controls_fullsample_removeincome_df,
  robust_petition_appropriate_self_controls_leftonly_removeincome_df,
  robust_petition_appropriate_self_controls_rightonly_removeincome_df,
  # robust_petition_appropriate_self_controls_rrponly_removeincome_df,
  robust_sign_petition_others_controls_fullsample_removeincome_df,
  robust_sign_petition_others_controls_leftonly_removeincome_df,
  robust_sign_petition_others_controls_rightonly_removeincome_df,
  # robust_sign_petition_others_controls_rrponly_removeincome_df,
  robust_petition_appropriate_others_controls_fullsample_removeincome_df,
  robust_petition_appropriate_others_controls_leftonly_removeincome_df,
  robust_petition_appropriate_others_controls_rightonly_removeincome_df,
  # robust_petition_appropriate_others_controls_rrponly_removeincome_df,
  robust_delete_tweet_controls_fullsample_removeincome_df,
  robust_delete_tweet_controls_leftonly_removeincome_df,
  robust_delete_tweet_controls_rightonly_removeincome_df
  # robust_delete_tweet_controls_rrponly_removeincome_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_removeincome$sample <- factor(joined_models_controls_removeincome$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e15 <- dwplot(joined_models_controls_removeincome,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Treatment Conditions against Control Condition (With Controls, Income Removed)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))


ggsave(
  filename = "plots/fig_e15.png", plot = fig_e15,
  width = 15, height = 10
)

# Sensitive Item - Education Removed

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_removeeducation <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data)
sensitive_item_controls_leftonly_removeeducation <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only)
sensitive_item_controls_rightonly_removeeducation <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only)
# sensitive_item_controls_rrponly_removeeducation <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_removeeducation <- summ(sensitive_item_controls_fullsample_removeeducation, robust = "HC1")
robust_sensitive_item_controls_leftonly_removeeducation <- summ(sensitive_item_controls_leftonly_removeeducation, robust = "HC1")
robust_sensitive_item_controls_rightonly_removeeducation <- summ(sensitive_item_controls_rightonly_removeeducation, robust = "HC1")
# robust_sensitive_item_controls_rrponly_removeeducation <- summ(sensitive_item_controls_rrponly_removeeducation, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_removeeducation_df <- broom::tidy(robust_sensitive_item_controls_fullsample_removeeducation) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_removeeducation_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_removeeducation_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_removeeducation_df <- broom::tidy(robust_sensitive_item_controls_leftonly_removeeducation) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_removeeducation_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_removeeducation_df)[7] <- "term"


robust_sensitive_item_controls_rightonly_removeeducation_df <- broom::tidy(robust_sensitive_item_controls_rightonly_removeeducation) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_removeeducation_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_removeeducation_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_removeeducation_df <- broom::tidy(robust_sensitive_item_controls_rrponly_removeeducation) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_removeeducation_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_removeeducation_df)[7] <- "term"


# Willingness to Sign Petition- remove education


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_removeeducation <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data)
sign_petition_self_controls_leftonly_removeeducation <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only)
sign_petition_self_controls_rightonly_removeeducation <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only)
# sign_petition_self_controls_rrponly_removeeducation <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only)

# robust SEs
robust_sign_petition_self_controls_fullsample_removeeducation <- summ(sign_petition_self_controls_fullsample_removeeducation, robust = "HC1")
robust_sign_petition_self_controls_leftonly_removeeducation <- summ(sign_petition_self_controls_leftonly_removeeducation, robust = "HC1")
robust_sign_petition_self_controls_rightonly_removeeducation <- summ(sign_petition_self_controls_rightonly_removeeducation, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_removeeducation <- summ(sign_petition_self_controls_rrponly_removeeducation, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_removeeducation_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_removeeducation) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_removeeducation_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_removeeducation_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_removeeducation_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_removeeducation) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_removeeducation_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_removeeducation_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_removeeducation_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_removeeducation) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_removeeducation_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_removeeducation_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_removeeducation_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_removeeducation) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_removeeducation_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_removeeducation_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - remove education

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_removeeducation <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data)
petition_appropriate_self_controls_leftonly_removeeducation <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only)
petition_appropriate_self_controls_rightonly_removeeducation <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only)
# petition_appropriate_self_controls_rrponly_removeeducation <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_removeeducation <- summ(petition_appropriate_self_controls_fullsample_removeeducation, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_removeeducation <- summ(petition_appropriate_self_controls_leftonly_removeeducation, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_removeeducation <- summ(petition_appropriate_self_controls_rightonly_removeeducation, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_removeeducation <- summ(petition_appropriate_self_controls_rrponly_removeeducation, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_removeeducation_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_removeeducation) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_removeeducation_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_removeeducation_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_removeeducation_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_removeeducation) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_removeeducation_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_removeeducation_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_removeeducation_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_removeeducation) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_removeeducation_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_removeeducation_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_removeeducation_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_removeeducation) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_removeeducation_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_removeeducation_df)[7] <- "term"



# Empirical Expectations - remove education

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_removeeducation <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data)
sign_petition_others_controls_leftonly_removeeducation <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only)
sign_petition_others_controls_rightonly_removeeducation <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only)
# sign_petition_others_controls_rrponly_removeeducation <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only)

# robust SEs
robust_sign_petition_others_controls_fullsample_removeeducation <- summ(sign_petition_others_controls_fullsample_removeeducation, robust = "HC1")
robust_sign_petition_others_controls_leftonly_removeeducation <- summ(sign_petition_others_controls_leftonly_removeeducation, robust = "HC1")
robust_sign_petition_others_controls_rightonly_removeeducation <- summ(sign_petition_others_controls_rightonly_removeeducation, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_removeeducation <- summ(sign_petition_others_controls_rrponly_removeeducation, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_removeeducation_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_removeeducation) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_removeeducation_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_removeeducation_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_removeeducation_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_removeeducation) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_removeeducation_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_removeeducation_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_removeeducation_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_removeeducation) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_removeeducation_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_removeeducation_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_removeeducation_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_removeeducation) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_removeeducation_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_removeeducation_df)[7] <- "term"



# Normative Expectations - remove education

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_removeeducation <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data)
petition_appropriate_others_controls_leftonly_removeeducation <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only)
petition_appropriate_others_controls_rightonly_removeeducation <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only)
# petition_appropriate_others_controls_rrponly_removeeducation <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_removeeducation <- summ(petition_appropriate_others_controls_fullsample_removeeducation, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_removeeducation <- summ(petition_appropriate_others_controls_leftonly_removeeducation, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_removeeducation <- summ(petition_appropriate_others_controls_rightonly_removeeducation, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_removeeducation <- summ(petition_appropriate_others_controls_rrponly_removeeducation, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_removeeducation_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_removeeducation) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_removeeducation_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_removeeducation_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_removeeducation_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_removeeducation) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_removeeducation_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_removeeducation_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_removeeducation_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_removeeducation) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_removeeducation_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_removeeducation_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_removeeducation_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_removeeducation) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_removeeducation_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_removeeducation_df)[7] <- "term"



# Sanctioning - remove education

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_removeeducation <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data)
delete_tweet_controls_leftonly_removeeducation <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only)
delete_tweet_controls_rightonly_removeeducation <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only)
# delete_tweet_controls_rrponly_removeeducation <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only)

# robust SEs
robust_delete_tweet_controls_fullsample_removeeducation <- summ(delete_tweet_controls_fullsample_removeeducation, robust = "HC1")
robust_delete_tweet_controls_leftonly_removeeducation <- summ(delete_tweet_controls_leftonly_removeeducation, robust = "HC1")
robust_delete_tweet_controls_rightonly_removeeducation <- summ(delete_tweet_controls_rightonly_removeeducation, robust = "HC1")
# robust_delete_tweet_controls_rrponly_removeeducation <- summ(delete_tweet_controls_rrponly_removeeducation, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_removeeducation_df <- broom::tidy(robust_delete_tweet_controls_fullsample_removeeducation) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_removeeducation_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_removeeducation_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_removeeducation_df <- broom::tidy(robust_delete_tweet_controls_leftonly_removeeducation) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_removeeducation_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_removeeducation_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_removeeducation_df <- broom::tidy(robust_delete_tweet_controls_rightonly_removeeducation) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_removeeducation_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_removeeducation_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_removeeducation_df <- broom::tidy(robust_delete_tweet_controls_rrponly_removeeducation) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_removeeducation_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_removeeducation_df)[7] <- "term"

# final joining of all the models
joined_models_controls_removeeducation <- rbind(
  robust_sign_petition_self_controls_fullsample_removeeducation_df,
  robust_sign_petition_self_controls_leftonly_removeeducation_df,
  robust_sign_petition_self_controls_rightonly_removeeducation_df,
  # robust_sign_petition_self_controls_rrponly_removeeducation_df,
  robust_sensitive_item_controls_fullsample_removeeducation_df,
  robust_sensitive_item_controls_leftonly_removeeducation_df,
  robust_sensitive_item_controls_rightonly_removeeducation_df,
  # robust_sensitive_item_controls_rrponly_removeeducation_df,
  robust_petition_appropriate_self_controls_fullsample_removeeducation_df,
  robust_petition_appropriate_self_controls_leftonly_removeeducation_df,
  robust_petition_appropriate_self_controls_rightonly_removeeducation_df,
  # robust_petition_appropriate_self_controls_rrponly_removeeducation_df,
  robust_sign_petition_others_controls_fullsample_removeeducation_df,
  robust_sign_petition_others_controls_leftonly_removeeducation_df,
  robust_sign_petition_others_controls_rightonly_removeeducation_df,
  # robust_sign_petition_others_controls_rrponly_removeeducation_df,
  robust_petition_appropriate_others_controls_fullsample_removeeducation_df,
  robust_petition_appropriate_others_controls_leftonly_removeeducation_df,
  robust_petition_appropriate_others_controls_rightonly_removeeducation_df,
  # robust_petition_appropriate_others_controls_rrponly_removeeducation_df,
  robust_delete_tweet_controls_fullsample_removeeducation_df,
  robust_delete_tweet_controls_leftonly_removeeducation_df,
  robust_delete_tweet_controls_rightonly_removeeducation_df
  # robust_delete_tweet_controls_rrponly_removeeducation_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_removeeducation$sample <- factor(joined_models_controls_removeeducation$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e14 <- dwplot(joined_models_controls_removeeducation,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Treatment Conditions against Control Condition (With Controls, Education Removed)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e14.png", plot = fig_e14,
  width = 15, height = 10
)

# Sensitive Item - left right removed

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_removeleftright <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = analysis_data)
sensitive_item_controls_leftonly_removeleftright <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = left_only)
sensitive_item_controls_rightonly_removeleftright <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = right_only)
# sensitive_item_controls_rrponly_removeleftright <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + education, data = rrp_only)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_removeleftright <- summ(sensitive_item_controls_fullsample_removeleftright, robust = "HC1")
robust_sensitive_item_controls_leftonly_removeleftright <- summ(sensitive_item_controls_leftonly_removeleftright, robust = "HC1")
robust_sensitive_item_controls_rightonly_removeleftright <- summ(sensitive_item_controls_rightonly_removeleftright, robust = "HC1")
# robust_sensitive_item_controls_rrponly_removeleftright <- summ(sensitive_item_controls_rrponly_removeleftright, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_removeleftright_df <- broom::tidy(robust_sensitive_item_controls_fullsample_removeleftright) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_removeleftright_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_removeleftright_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_removeleftright_df <- broom::tidy(robust_sensitive_item_controls_leftonly_removeleftright) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_removeleftright_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_removeleftright_df)[7] <- "term"


robust_sensitive_item_controls_rightonly_removeleftright_df <- broom::tidy(robust_sensitive_item_controls_rightonly_removeleftright) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_removeleftright_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_removeleftright_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_removeleftright_df <- broom::tidy(robust_sensitive_item_controls_rrponly_removeleftright) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_removeleftright_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_removeleftright_df)[7] <- "term"


# Willingness to Sign Petition- left right remove


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_removeleftright <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = analysis_data)
sign_petition_self_controls_leftonly_removeleftright <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = left_only)
sign_petition_self_controls_rightonly_removeleftright <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = right_only)
# sign_petition_self_controls_rrponly_removeleftright <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + education, data = rrp_only)

# robust SEs
robust_sign_petition_self_controls_fullsample_removeleftright <- summ(sign_petition_self_controls_fullsample_removeleftright, robust = "HC1")
robust_sign_petition_self_controls_leftonly_removeleftright <- summ(sign_petition_self_controls_leftonly_removeleftright, robust = "HC1")
robust_sign_petition_self_controls_rightonly_removeleftright <- summ(sign_petition_self_controls_rightonly_removeleftright, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_removeleftright <- summ(sign_petition_self_controls_rrponly_removeleftright, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_removeleftright_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_removeleftright) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_removeleftright_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_removeleftright_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_removeleftright_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_removeleftright) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_removeleftright_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_removeleftright_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_removeleftright_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_removeleftright) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_removeleftright_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_removeleftright_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_removeleftright_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_removeleftright) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_removeleftright_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_removeleftright_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - left right removed

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_removeleftright <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = analysis_data)
petition_appropriate_self_controls_leftonly_removeleftright <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = left_only)
petition_appropriate_self_controls_rightonly_removeleftright <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = right_only)
# petition_appropriate_self_controls_rrponly_removeleftright <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + education, data = rrp_only)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_removeleftright <- summ(petition_appropriate_self_controls_fullsample_removeleftright, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_removeleftright <- summ(petition_appropriate_self_controls_leftonly_removeleftright, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_removeleftright <- summ(petition_appropriate_self_controls_rightonly_removeleftright, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_removeleftright <- summ(petition_appropriate_self_controls_rrponly_removeleftright, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_removeleftright_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_removeleftright) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_removeleftright_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_removeleftright_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_removeleftright_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_removeleftright) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_removeleftright_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_removeleftright_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_removeleftright_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_removeleftright) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_removeleftright_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_removeleftright_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_removeleftright_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_removeleftright) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_removeleftright_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_removeleftright_df)[7] <- "term"



# Empirical Expectations - left right removed

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_removeleftright <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = analysis_data)
sign_petition_others_controls_leftonly_removeleftright <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = left_only)
sign_petition_others_controls_rightonly_removeleftright <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = right_only)
# sign_petition_others_controls_rrponly_removeleftright <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + education, data = rrp_only)

# robust SEs
robust_sign_petition_others_controls_fullsample_removeleftright <- summ(sign_petition_others_controls_fullsample_removeleftright, robust = "HC1")
robust_sign_petition_others_controls_leftonly_removeleftright <- summ(sign_petition_others_controls_leftonly_removeleftright, robust = "HC1")
robust_sign_petition_others_controls_rightonly_removeleftright <- summ(sign_petition_others_controls_rightonly_removeleftright, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_removeleftright <- summ(sign_petition_others_controls_rrponly_removeleftright, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_removeleftright_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_removeleftright) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_removeleftright_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_removeleftright_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_removeleftright_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_removeleftright) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_removeleftright_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_removeleftright_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_removeleftright_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_removeleftright) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_removeleftright_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_removeleftright_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_removeleftright_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_removeleftright) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_removeleftright_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_removeleftright_df)[7] <- "term"



# Normative Expectations - left right removed

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_removeleftright <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = analysis_data)
petition_appropriate_others_controls_leftonly_removeleftright <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = left_only)
petition_appropriate_others_controls_rightonly_removeleftright <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = right_only)
# petition_appropriate_others_controls_rrponly_removeleftright <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + education, data = rrp_only)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_removeleftright <- summ(petition_appropriate_others_controls_fullsample_removeleftright, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_removeleftright <- summ(petition_appropriate_others_controls_leftonly_removeleftright, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_removeleftright <- summ(petition_appropriate_others_controls_rightonly_removeleftright, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_removeleftright <- summ(petition_appropriate_others_controls_rrponly_removeleftright, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_removeleftright_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_removeleftright) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_removeleftright_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_removeleftright_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_removeleftright_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_removeleftright) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_removeleftright_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_removeleftright_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_removeleftright_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_removeleftright) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_removeleftright_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_removeleftright_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_removeleftright_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_removeleftright) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_removeleftright_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_removeleftright_df)[7] <- "term"



# Sanctioning - left right removed

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_removeleftright <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = analysis_data)
delete_tweet_controls_leftonly_removeleftright <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = left_only)
delete_tweet_controls_rightonly_removeleftright <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + education, data = right_only)
# delete_tweet_controls_rrponly_removeleftright <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + education, data = rrp_only)

# robust SEs
robust_delete_tweet_controls_fullsample_removeleftright <- summ(delete_tweet_controls_fullsample_removeleftright, robust = "HC1")
robust_delete_tweet_controls_leftonly_removeleftright <- summ(delete_tweet_controls_leftonly_removeleftright, robust = "HC1")
robust_delete_tweet_controls_rightonly_removeleftright <- summ(delete_tweet_controls_rightonly_removeleftright, robust = "HC1")
# robust_delete_tweet_controls_rrponly_removeleftright <- summ(delete_tweet_controls_rrponly_removeleftright, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_removeleftright_df <- broom::tidy(robust_delete_tweet_controls_fullsample_removeleftright) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_removeleftright_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_removeleftright_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_removeleftright_df <- broom::tidy(robust_delete_tweet_controls_leftonly_removeleftright) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_removeleftright_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_removeleftright_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_removeleftright_df <- broom::tidy(robust_delete_tweet_controls_rightonly_removeleftright) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_removeleftright_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_removeleftright_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_removeleftright_df <- broom::tidy(robust_delete_tweet_controls_rrponly_removeleftright) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_removeleftright_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_removeleftright_df)[7] <- "term"

# final joining of all the models
joined_models_controls_removeleftright <- rbind(
  robust_sign_petition_self_controls_fullsample_removeleftright_df,
  robust_sign_petition_self_controls_leftonly_removeleftright_df,
  robust_sign_petition_self_controls_rightonly_removeleftright_df,
  # robust_sign_petition_self_controls_rrponly_removeleftright_df,
  robust_sensitive_item_controls_fullsample_removeleftright_df,
  robust_sensitive_item_controls_leftonly_removeleftright_df,
  robust_sensitive_item_controls_rightonly_removeleftright_df,
  # robust_sensitive_item_controls_rrponly_removeleftright_df,
  robust_petition_appropriate_self_controls_fullsample_removeleftright_df,
  robust_petition_appropriate_self_controls_leftonly_removeleftright_df,
  robust_petition_appropriate_self_controls_rightonly_removeleftright_df,
  # robust_petition_appropriate_self_controls_rrponly_removeleftright_df,
  robust_sign_petition_others_controls_fullsample_removeleftright_df,
  robust_sign_petition_others_controls_leftonly_removeleftright_df,
  robust_sign_petition_others_controls_rightonly_removeleftright_df,
  # robust_sign_petition_others_controls_rrponly_removeleftright_df,
  robust_petition_appropriate_others_controls_fullsample_removeleftright_df,
  robust_petition_appropriate_others_controls_leftonly_removeleftright_df,
  robust_petition_appropriate_others_controls_rightonly_removeleftright_df,
  # robust_petition_appropriate_others_controls_rrponly_removeleftright_df,
  robust_delete_tweet_controls_fullsample_removeleftright_df,
  robust_delete_tweet_controls_leftonly_removeleftright_df,
  robust_delete_tweet_controls_rightonly_removeleftright_df
  # robust_delete_tweet_controls_rrponly_removeleftright_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_removeleftright$sample <- factor(joined_models_controls_removeleftright$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e16 <- dwplot(joined_models_controls_removeleftright,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Treatment Conditions against Control Condition (With Controls, Left-Right Self Placement Removed)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e16.png", plot = fig_e16,
  width = 15, height = 10
)
